<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>透明的单例类的编写优化版</title>
</head>
<body>
<script>
    var CreateDiv = (function () {
        var instance ;
      var CreateDiv = function (html) {
          this.html = html;
          this.init();
      };
      CreateDiv.prototype.init = function () {
          var div = document.createElement('div');
          div.innerHTML = this.html;
          document.body.appendChild(div);
      };
      return CreateDiv;
    })();
    var ProxySingletonCreateDiv = (function () {
        var instance;
        return function (html) {
            if(!instance){
                instance = new CreateDiv(html);
            }
            return instance;
        }
    })()
    var a = new ProxySingletonCreateDiv('sven1');
    var b = new ProxySingletonCreateDiv('sven2');
    alert(a===b);



</script>
</body>
</html>